CREATE TABLE [dbo].[LikeDislike](
	[CustomerID]	[int] NOT NULL,
	[ProductID] [int] NOT NULL,
	[LikeDislike] [int] NOT NULL,
	PRIMARY KEY ([CustomerID],[ProductID])	  
	);
	
CREATE TABLE [dbo].[Comment](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[ProductID] [int] NOT NULL,
	[Contents] [nvarchar](500) NOT NULL,
	[CustomerID] [int] NOT NULL,
	[PostDate] [datetime] NOT NULL,	
	PRIMARY KEY ([ID])
	);

CREATE TABLE [dbo].[ProductCategory](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](30) NOT NULL,	
	[CreateDate] datetime NOT NULL,
	[UpdateDate] datetime NULL,
	[Status] int NOT NULL,
	PRIMARY KEY ([ID])
	);
	
CREATE TABLE [dbo].[Product](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[ProductCategoryID] [int] NULL,
	[Name] [nvarchar](30) NOT NULL,
	[Detail] [nvarchar](500) NOT NULL,
	[FloorPrice] [money] NOT NULL,
	[StepPrice] [money] NOT NULL,
	[CurrentPrice] [money] NULL,
	[BeginDate] [datetime] NULL,
	[UpdateDate] [datetime] NULL,
	[TotalBidDay] [int] NULL,
	[SellerID] [int] NOT NULL,
	[BuyerID] [int] NULL,	
	[SellerRating] [int] NULL,
	[BuyerRating] [int] NULL,
	[Status] [int] NOT NULL,
	[PlusMinute] [int] NOT NULL,
	PRIMARY KEY ([ID])
	);
	
CREATE TABLE [dbo].[ProductImage](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[ProductID] [int] NOT NULL,
	[Url] [nvarchar](500) NOT NULL,
	PRIMARY KEY ([ID])
	);	
	
CREATE TABLE [dbo].[Customer](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[Sellable] [int] NOT NULL,
	[Email] [nvarchar](100) NOT NULL,
	[Password] [nvarchar](50) NOT NULL,
	[FullName] [nvarchar](50) NOT NULL,
	[Phone] [nvarchar](20) NOT NULL,
	[Address] [nvarchar](100) NOT NULL,
	PRIMARY KEY ([ID])
	);	
	
CREATE TABLE [dbo].[AuctionLog](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[ProductID] [int] NOT NULL,
	[BuyerID] [int] NOT NULL,
	[BidDate] [datetime] NOT NULL,
	[Price] [money] NOT NULL,
	[Status] [int] NOT NULL,
	PRIMARY KEY ([ID])
	);	
	
CREATE TABLE [dbo].[Member](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[UserName] [nvarchar](50) NOT NULL,
	[FullName] [nvarchar](50) NOT NULL,
	[Password] [nvarchar](50) NOT NULL,
	[Role] [int] NOT NULL,
	[LastLogOnDate] [datetime] NOT NULL,
	PRIMARY KEY ([ID])
	);	
	
Alter TABLE [dbo].[LikeDislike] add constraint FK_LikeDislike_CustomerID
foreign key([CustomerID]) references [dbo].[Customer]([ID])	

Alter TABLE [dbo].[LikeDislike] add constraint FK_LikeDislike_ProductID
foreign key([ProductID]) references [dbo].[Product]([ID])		

Alter TABLE [dbo].[ProductImage] add constraint FK_ProductImage_ProductID
foreign key([ProductID]) references [dbo].[Product]([ID])		

Alter TABLE [dbo].[AuctionLog] add constraint FK_AuctionLog_ProductID
foreign key([ProductID]) references [dbo].[Product]([ID])		

Alter TABLE [dbo].[AuctionLog] add constraint FK_AuctionLog_BuyerID
foreign key([BuyerID]) references [dbo].[Customer]([ID])	

Alter TABLE [dbo].[Comment] add constraint FK_Comment_ProductID
foreign key([ProductID]) references [dbo].[Product]([ID])		

Alter TABLE [dbo].[Comment] add constraint FK_Comment_CustomerID
foreign key([CustomerID]) references [dbo].[Customer]([ID])	

Alter TABLE [dbo].[Product] add constraint FK_Product_ProductCategoryID
foreign key([ProductCategoryID]) references [dbo].[ProductCategory]([ID])	

Alter TABLE [dbo].[Product] add constraint FK_Product_SellerID
foreign key([SellerID]) references [dbo].[Customer]([ID])	

Alter TABLE [dbo].[Product] add constraint FK_Product_BuyerID
foreign key([BuyerID]) references [dbo].[Customer]([ID])		
